import java.util.HashMap;
import java.util.Stack;

public class t20_dome {
    public static void main(String[] args) {
        System.out.println(isValid("){"));
        System.out.println(86|32);
    }
    public static boolean isValid(String s) {
        if(s.length()%2==1){
            return false;
        }
        Stack<Character> stack = new Stack<>();
        char arr[] = s.toCharArray();
        HashMap<Character,Character> map = new HashMap<>();
        map.put('(',')');
        map.put('{','}');
        map.put('[',']');
        for(int i = 0;i<s.length();i++){
            if(arr[i] =='(' || arr[i] =='[' || arr[i] == '{'){
                stack.push(arr[i]);
            }else if(!stack.empty()){
                Character peek = stack.peek();
                if(map.get(peek) == arr[i]){
                    stack.pop();
                }else{
                    return false;
                }
            }else{
                return false;
            }
        }
        if(stack.size() == 0){
            return true;
        }else{
            return false;
        }
    }
}
